<?php

namespace app\admin\controller;

use app\BaseController;

class Study extends BaseController
{
    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function subject()
    {
        try {
            $subjectObj = new \app\common\business\Subject();
            $result = $subjectObj->subject();
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function courseware()
    {
        $list_rows = $this->request->param('list_rows', '10', 'trim');
        $page = $this->request->param('page', '1', 'trim');
        $subject_id = $this->request->param('subject_id', '', 'trim');

        $data = [
            'subject_id' => $subject_id,
            'list_rows' => $list_rows,
            'page' => $page,
        ];

        $data = array_filter($data);
        try {
            $coursewareObj = new \app\common\business\Courseware();
            $result = $coursewareObj->courseware($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function one_courseware()
    {
        $id = $this->request->param('id', '', 'trim');

        try {
            $coursewareObj = new \app\common\business\Courseware();
            $result = $coursewareObj->one_courseware($id);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function add_courseware()
    {
        $number = $this->request->param('number', '', 'trim');
        $name = $this->request->param('name', '', 'trim');
        $subject_id = $this->request->param('subject_id', '', 'trim');
        $content = $this->request->param('content', '', 'trim');
        $data = [
            'number' => $number,
            'name' => $name,
            'subject_id' => $subject_id,
            'content' => $content,
        ];

        $data = array_filter($data);
        try {
            $coursewareObj = new \app\common\business\Courseware();
            $result = $coursewareObj->add_courseware($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }


    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function del_courseware()
    {
        $id = $this->request->param('id', '', 'trim');
        try {
            $coursewareObj = new \app\common\business\Courseware();
            $result = $coursewareObj->del_courseware($id);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function edit_courseware()
    {
        $id = $this->request->param('id', '', 'trim');
        $number = $this->request->param('number', '', 'trim');
        $name = $this->request->param('name', '', 'trim');
        $subject_id = $this->request->param('subject_id', '', 'trim');
        $content = $this->request->param('content', '', 'trim');
        $codes = $this->request->param('codes', '', 'trim');
        $data = [
            'id' => $id,
            'number' => $number,
            'name' => $name,
            'subject_id' => $subject_id,
            'content' => $content,
            'codes' => $codes,
        ];
        $data = array_filter($data);

        try {
            $coursewareObj = new \app\common\business\Courseware();
            $result = $coursewareObj->edit_courseware($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }


    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function exercises()
    {
        $list_rows = $this->request->param('list_rows', '10', 'trim');
        $page = $this->request->param('page', '1', 'trim');
        $subject_id = $this->request->param('subject_id', '', 'trim');

        $data = [
            'subject_id' => $subject_id,
            'list_rows' => $list_rows,
            'page' => $page,
        ];

        $data = array_filter($data);
        try {
            $exercisesObj = new \app\common\business\Exercises();
            $result = $exercisesObj->exercises($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function exercises_all()
    {
        $subject_id = $this->request->param('subject_id', '', 'trim');

        $data = [
            'subject_id' => $subject_id,
        ];

        $data = array_filter($data);
        try {
            $exercisesObj = new \app\common\business\Exercises();
            $result = $exercisesObj->exercises_all($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function one_exercises()
    {
        $id = $this->request->param('id', '', 'trim');
        try {
            $exercisesObj = new \app\common\business\Exercises();
            $result = $exercisesObj->one_exercises($id);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function add_exercises()
    {
        $number = $this->request->param('number', '', 'trim');
        $name = $this->request->param('name', '', 'trim');
        $subject_id = $this->request->param('subject_id', '', 'trim');
        $tag = $this->request->param('tag', '', 'trim');
        $data = [
            'number' => $number,
            'name' => $name,
            'subject_id' => $subject_id,
            'tag' => $tag,
        ];

        $data = array_filter($data);
        try {
            $exercisesObj = new \app\common\business\Exercises();
            $result = $exercisesObj->add_exercises($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }


    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function del_exercises()
    {
        $id = $this->request->param('id', '', 'trim');
        try {
            $exercisesObj = new \app\common\business\Exercises();
            $result = $exercisesObj->del_exercises($id);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function edit_exercises()
    {
        $id = $this->request->param('id', '', 'trim');
        $number = $this->request->param('number', '', 'trim');
        $name = $this->request->param('name', '', 'trim');
        $subject_id = $this->request->param('subject_id', '', 'trim');
        $tag = $this->request->param('tag', '', 'trim');
        $content = $this->request->param('content', '', 'trim');
        $data = [
            'id' => $id,
            'number' => $number,
            'name' => $name,
            'subject_id' => $subject_id,
            'tag' => $tag,
            'content' => $content,
        ];
        $data = array_filter($data);
        try {
            $exercisesObj = new \app\common\business\Exercises();
            $result = $exercisesObj->edit_exercises($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }


    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function classwork()
    {
        $list_rows = $this->request->param('list_rows', '10', 'trim');
        $page = $this->request->param('page', '1', 'trim');
        $subject_id = $this->request->param('subject_id', '', 'trim');

        $data = [
            'subject_id' => $subject_id,
            'list_rows' => $list_rows,
            'page' => $page,
        ];

        $data = array_filter($data);
        try {
            $classworkObj = new \app\common\business\Classwork();
            $result = $classworkObj->classwork($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function one_classwork()
    {
        $id = $this->request->param('id', '', 'trim');

        try {
            $classworkObj = new \app\common\business\Classwork();
            $result = $classworkObj->one_classwork($id);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function add_classwork()
    {
        $name = $this->request->param('name', '', 'trim');
        $subject_id = $this->request->param('subject_id', '', 'trim');
        $classes_ids = $this->request->param('classes_ids', '', 'trim');
        $exercises_id = $this->request->param('exercises_id', '', 'trim');
        $data = [
            'name' => $name,
            'subject_id' => $subject_id,
            'classes_ids' => json_encode($classes_ids),
            'exercises_id' => $exercises_id,
        ];

        $data = array_filter($data);
        try {
            $classworkObj = new \app\common\business\Classwork();
            $result = $classworkObj->add_classwork($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }


    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function del_classwork()
    {
        $id = $this->request->param('id', '', 'trim');
        try {
            $classworkObj = new \app\common\business\Classwork();
            $result = $classworkObj->del_classwork($id);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function edit_classwork()
    {
        $id = $this->request->param('id', '', 'trim');
        $name = $this->request->param('name', '', 'trim');
        $subject_id = $this->request->param('subject_id', '', 'trim');
        $content = $this->request->param('content', '', 'trim');
        $data = [
            'id' => $id,
            'name' => $name,
            'subject_id' => $subject_id,
            'content' => $content,
        ];
        $data = array_filter($data);
        try {
            $classworkObj = new \app\common\business\Classwork();
            $result = $classworkObj->edit_classwork($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }


    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function study_report()
    {
        $list_rows = $this->request->param('list_rows', '10', 'trim');
        $page = $this->request->param('page', '1', 'trim');
        $classes_id = $this->request->param('classes_id', '', 'trim');
        $time = $this->request->param('time', '', 'trim');

        $data = [
            'classes_id' => $classes_id,
            'list_rows' => $list_rows,
            'page' => $page,
            'time' => $time . '',
        ];

        $data = array_filter($data);
        try {
            $study_reportObj = new \app\common\business\StudyReport();
            $result = $study_reportObj->study_report($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function one_study_report()
    {
        $id = $this->request->param('id', '', 'trim');

        try {
            $study_reportObj = new \app\common\business\StudyReport();
            $result = $study_reportObj->one_study_report($id);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function add_study_report()
    {
        $name = $this->request->param('name', '', 'trim');
        $classes_id = $this->request->param('classes_id', '', 'trim');
        $data = [
            'name' => $name,
            'classes_id' => $classes_id,
        ];

        $data = array_filter($data);
        try {
            $study_reportObj = new \app\common\business\StudyReport();
            $result = $study_reportObj->add_study_report($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }


    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function del_study_report()
    {
        $id = $this->request->param('id', '', 'trim');
        try {
            $study_reportObj = new \app\common\business\StudyReport();
            $result = $study_reportObj->del_study_report($id);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function edit_study_report()
    {
        $id = $this->request->param('id', '', 'trim');
        $img = $this->request->param('img', '', 'trim');
        $title = $this->request->param('title', '', 'trim');
        $video = $this->request->param('video', '', 'trim');
        $content = $this->request->param('content', '', 'trim');
        $data = [
            'id' => $id,
            'title' => $title,
            'img' => json_encode($img),
            'video' => $video,
            'content' => $content,
        ];
        $data = array_filter($data);
        $data['video'] = $video;
        try {
            $study_reportObj = new \app\common\business\StudyReport();
            $result = $study_reportObj->edit_study_report($data,320);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

}